package com.wsd.jing.request;

import com.wsd.jing.enums.CodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author tom
 * @version 1.0.0
 * @projectName: jing
 * @packageName: com.wsd.jing.result
 * @className: CommonResponse
 * @description 通用返回对象
 * @createDate 2022/11/14 10:40
 * @copyright 2022/11/14 10:40 www.tom.com Inc. All rights reserved.
 */
@Setter
@Getter
@ApiModel(value = "CommonResponse对象", description = "公共返回对象")
public class CommonResponse<T> {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("返回信息")
    private String message;

    @ApiModelProperty("返回数据")
    private T data;

    protected CommonResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * @param data:返回数据
     * @return CommonResponse<T>
     * @author tom
     * @description 成功返回结果
     * @createDate 2022/11/30 12:42
     */
    public static <T> CommonResponse<T> success(T data) {
        return new CommonResponse<T>(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMessage(), data);
    }

    /**
     * @param data:返回数据
     * @param message:返回信息
     * @return CommonResponse<T>
     * @author tom
     * @description 成功返回结果
     * @createDate 2022/11/30 12:43
     */
    public static <T> CommonResponse<T> success(T data, String message) {
        return new CommonResponse<T>(CodeEnum.SUCCESS.getCode(), message, data);
    }

    /**
     * @param message:返回信息
     * @return CommonResponse<T>
     * @author tom
     * @description 失败返回结果
     * @createDate 2022/11/30 12:44
     */
    public static <T> CommonResponse<T> failed(String message) {
        return new CommonResponse<T>(CodeEnum.FAILED.getCode(), message, null);
    }

    /**
     * @param code:状态码
     * @param message:返回信息
     * @return CommonResponse<T>
     * @author tom
     * @description 失败返回结果
     * @createDate 2024/7/3 17:45
     */
    public static <T> CommonResponse<T> failed(Integer code, String message) {
        return new CommonResponse<T>(code, message, null);
    }

    /**
     * @param codeEnum:状态码枚举
     * @return CommonResponse<T>
     * @author tom
     * @description 失败返回结果
     * @createDate 2024/7/2 18:12
     */
    public static <T> CommonResponse<T> failed(CodeEnum codeEnum) {
        return new CommonResponse<T>(codeEnum.getCode(), codeEnum.getMessage(), null);
    }

    /**
     * @param codeEnum:状态码枚举
     * @param message:返回信息
     * @return CommonResponse<T>
     * @author tom
     * @description 失败返回结果
     * @createDate 2024/7/3 17:42
     */
    public static <T> CommonResponse<T> failed(CodeEnum codeEnum, String message) {
        return new CommonResponse<T>(codeEnum.getCode(), message, null);
    }
}
